// 引入路由组件
import Home from "@/pages/Home";
import Login from "@/pages/Login/";
import Register from "@/pages/Register";
import Search from "@/pages/Search";
import Detail from "@/pages/Detail";
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'

// 导出路由配置
export default [{
        path: "*",
        redirect: "/home",
    },
    {
        path: "/home",
        component: Home,
        meta: {
            show: true,
        },
    },
    {
        path: "/login",
        component: Login,
        meta: {
            show: false,
        },
    },
    {
        path: "/register",
        component: Register,
        meta: {
            show: false,
        },
    },
    {
        // 路由传参
        name: "search",
        path: "/search/:keyword?",
        component: Search,
        meta: {
            show: true,
        }
    },
    {
        name: "detail",
        path: "/detail/:skuId",
        component: Detail,
        meta: {
            show: true,
        }
    },
    {
        name: "addcartsuccess",
        path: "/addcartsuccess",
        component: AddCartSuccess,
        meta: {
            show: true,
        }
    },
    {
        name: "shopcart",
        path: "/shopcart",
        component: ShopCart,
        meta: {
            show: true,
        }
    }, {
        name: "trade",
        path: "/trade",
        component: Trade,
        meta: {
            show: true,
        },
        beforeEnter: (to, from, next) => {
            if (from.path == '/shopcart') {
                next();
            } else {
                next(false);
            }
        }
    }, {
        name: "pay",
        path: "/pay",
        component: Pay,
        meta: {
            show: true,
        },
        beforeEnter: (to, from, next) => {
            if (from.path == '/trade') {
                next();
            } else {
                next(false);
            }
        }
    },
    {
        name: "paysuccess",
        path: "/paysuccess",
        component: PaySuccess,
        meta: {
            show: true,
        },
        beforeEnter: (to, from, next) => {
            if (from.path == '/pay') {
                next();
            } else {
                next(false);
            }
        }
    }, {
        name: "center",
        path: "/center",
        component: Center,
        meta: {
            show: true,
        }
    }

]